package com.dddpeter.app.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dddpeter.app.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    
    @Select("SELECT * FROM users WHERE username = #{username}")
    User findByUsername(@Param("username") String username);
    
    @Select("SELECT * FROM users WHERE email = #{email}")
    User findByEmail(@Param("email") String email);
    
    @Select("SELECT COUNT(*) > 0 FROM users WHERE username = #{username}")
    boolean existsByUsername(@Param("username") String username);
    
    @Select("SELECT COUNT(*) > 0 FROM users WHERE email = #{email}")
    boolean existsByEmail(@Param("email") String email);
    
    @Select("SELECT * FROM users WHERE full_name LIKE '%' || #{name} || '%'")
    List<User> findByFullNameContaining(@Param("name") String name);
    
    @Select("SELECT * FROM users WHERE created_at >= #{startDate}")
    List<User> findUsersCreatedAfter(@Param("startDate") java.time.LocalDateTime startDate);
    
    @Select("SELECT MAX(id) FROM users")
    Long getMaxId();
}
